const axios = require('axios');

// 修正测试数据，确保customer_id是整数
const pluginData = {
  "batchId": "test_batch_" + Date.now(),
  "timestamp": new Date().toISOString(),
  "dataType": "sales_order",
  "data": [
    {
      "id": "req_test_" + Date.now(),
      "url": "/api/mall/order/list",
      "method": "POST",
      "timestamp": new Date().toISOString(),
      "request": {},
      "response": {
        "data": [
          {
            "data": [
              {
                "order": {
                  "id": "ORDER_TEST_001",
                  "purchaserId": 1001,  // 改为整数
                  "orderTotalFee": "1500.00",
                  "status": "4",
                  "createdAt": "2025-11-24T15:55:00.000Z",
                  "platformSource": "zcy",
                  "invoiceStatus": "invoiced"
                },
                "items": [
                  {
                    "itemId": "ITEM_TEST_001",
                    "itemName": "测试产品1",
                    "quantity": "3",
                    "skuPrice": "500.00",
                    "amount": "1500.00"
                  }
                ]
              }
            ]
          }
        ]
      },
      "ruleInfo": {
        "dataType": "sales_order"
      }
    }
  ]
};

console.log("准备发送测试数据到服务器...");
console.log("数据:", JSON.stringify(pluginData, null, 2));

// 发送数据到服务器
axios.post('http://127.0.0.1:9001/api/v1/plugin/data/receive', pluginData)
  .then(response => {
    console.log('✅ 服务器响应:', response.data);
    
    // 等待几秒钟让数据处理完成
    console.log('\n⏳ 等待数据处理完成...');
    setTimeout(() => {
      // 查询处理状态
      axios.get(`http://127.0.0.1:9001/api/v1/plugin/data/batches`)
        .then(statusResponse => {
          console.log('\n📊 批次列表:', statusResponse.data);
        })
        .catch(error => {
          console.error('❌ 查询批次列表失败:', error.message);
        });
    }, 3000);
  })
  .catch(error => {
    console.error('❌ 发送数据失败:', error.message);
    if (error.response) {
      console.error('📋 服务器响应:', error.response.data);
    }
  });